/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package jpa.session;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import jpa.entities.User;
import jpa.entities.UserGroup;

/**
 *
 * @author andreas
 */
@Stateless
public class UserFacade extends AbstractFacade<User> implements UserFacadeRemote {
    @PersistenceContext(unitName = "Bank-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UserFacade() {
        super(User.class);
    }

    @Override
    public void createTestUsers() {

        UserGroup ug;
        User u;

        u = new User();
        ug = new UserGroup();
        ug.setName("CUSTOMER");
        u.getUsergroups().add(ug);
        u.setUserid(123456);
        u.setPassword(123456);
        ug.getUsers().add(u);
        em.persist(ug);
        em.persist(u);

//        System.out.println("!!!!!!!!!!!!!!!!!!!");
//        System.out.println("group customer");
            //System.out.println(ug.getUsers().size());
//
////        UserGroup ug2 = new UserGroup();
////        ug2.setName("BANK TELLER");
////
////
////
////        em.persist(ug);
////        em.persist(u);
    }

}
